//
//  ServiceNetworkViewController.m
//  CPICMobileServiceApp
//
//  Created by lizhiwei on 13-2-4.
//  Copyright (c) 2013年 lizhiwei. All rights reserved.
//

#import "ServiceNetworkViewController.h"

#define MyNearNetBtnWidth 200
#define MyNearNetBtnHeight 30

@interface ServiceNetworkViewController ()

@end

@implementation ServiceNetworkViewController
@synthesize mapView;
@synthesize userLatitude;
@synthesize userlongitude;
@synthesize MyNearNetBtn;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
        self.title = @"服务网点查询";
        //self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773@2x"]];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    userLatitude=@"";
    userlongitude=@"";
    
	mapView = [[MKMapView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-140)];
    mapView.delegate = self;
    mapView.mapType=MKMapTypeStandard;
    [self.view addSubview:mapView];
    
    //添加“显示我附近的服务网点”按钮
    MyNearNetBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    NSLog(@"%f",self.view.frame.size.height);
    MyNearNetBtn.frame = CGRectMake((self.view.frame.size.width-MyNearNetBtnWidth)/2,330, MyNearNetBtnWidth, MyNearNetBtnHeight);
    [MyNearNetBtn setTitle:@"显示我附近的服务网点" forState:UIControlStateNormal];
    [MyNearNetBtn addTarget:self action:@selector(ClickMyNearNetBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:MyNearNetBtn];
}

-(void) ClickMyNearNetBtn
{
    mapView.showsUserLocation = YES;
    MKUserLocation *userLocation = mapView.userLocation;
    CLLocationCoordinate2D coordinate = userLocation.location.coordinate;
    if(!geo)
    {
        geo=[[MKReverseGeocoder alloc] initWithCoordinate:coordinate];
        geo.delegate = self;
        [geo start];
    }
    MKCoordinateSpan span;
    span.latitudeDelta = .001;
    span.longitudeDelta = .001;
    
    MKCoordinateRegion region;
    region.center = userLocation.coordinate;
    region.span = span;
    [mapView setRegion:region animated:TRUE];
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
{
}
- (void)viewDidUnload
{
    [super viewDidUnload];
    [mapView release];
    [MyNearNetBtn release];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
